
package gui.std;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

@SuppressWarnings("serial")
public class ImageChooser extends JFrame {
	
	public ImageChooser() {
		initialize();
	}
	
	private void initialize() {
		setSize(WIDTH, HEIGHT);
		setResizable(false);
		setTitle("Getting image ...");
		setLocationRelativeTo(null);
		
		pathImg = "./src/gui/std/icons/user/minIcon (1).png";
		
		File f = new File("./src/gui/std/icons/user");
		buttons = new JPanel(new GridLayout(0, 4));
		
		for (final File i : f.listFiles()) {
			if (i.getName().matches("min.*")) {
				JButton b = new JButton("", new ImageIcon(i.getAbsolutePath()));
				b.setFocusable(false);
				
				b.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						pathImg = i.getAbsolutePath();
						_this.setVisible(false);
					}
				});
				
				buttons.add(b);
			}
		}
		
		Container c = getContentPane();
		c.setLayout(new BorderLayout());
		c.add(new JScrollPane(buttons));
		
		setVisible(true);
	}
	
	public String getPathImage() {
		return pathImg;
	}
	
	private static final int WIDTH = 426;
	private static final int HEIGHT = 337;
	
	private JPanel buttons;
	private String pathImg;
	private JFrame _this = this;
}
